/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software Foundation,
 *    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package JET.Frames.DataModels;

import JET.Centers.ControlCenter;
import JET.Scene;
import java.util.ArrayList;
import javax.swing.ListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;

/**
 *
 * @author 057Ry
 */
public class TorquesListModel implements ListModel
{
    static final ControlCenter CC = ControlCenter.getInstance();
    private ArrayList<ListDataListener> listeners;
    private Scene scene;

    public TorquesListModel() {
        listeners = new ArrayList<ListDataListener>();
    }

    public void setScene(Scene s) {
        scene = s;
    }

    public int getSize() {
        if (CC!=null && scene!=null && scene.getJETContext()!=null)
            return scene.getJETContext().getTorqueList().size();
        else
            return 0;
    }

    public Object getElementAt(int index) {
        if (CC!=null && scene!=null && scene.getJETContext()!=null)
            return scene.getJETContext().getTorqueList().get(index);
        else
            return null;
    }

    public void fireTorquesListChanged() {
        for(ListDataListener l : listeners)
            l.contentsChanged( new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, getSize()-1));
    }

    public void addListDataListener(ListDataListener l) {
        listeners.add(l);
    }

    public void removeListDataListener(ListDataListener l) {
        listeners.remove(l);
    }
}
